package com.wuchao.servlet143;

import com.wuchao.entity.Pojo;
import com.wuchao.service.serviceimpl.ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 吴超66
 * @version 1.0
 * @date 2022/4/25 09:36
 */
@WebServlet(name = "ServletELJSTL",urlPatterns = "/ServletELJSTL")
public class ServletELJSTL extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //一定会乱码
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();//文件流
        out.println();
        //你设定拿值范围，request
        Pojo pojo = new Pojo();
        pojo.setName("对象");//对象
        List<Pojo> list=new ArrayList<>();
        list.add(pojo);
        Map<String,Pojo> map=new HashMap<>();
        List<Pojo> poJo = new ServiceImpl().findPoJo("select * from t143");
        map.put("001",pojo);
        request.setAttribute("pt","超哥");//我没有写作用域
        request.setAttribute("dx",pojo);
        request.setAttribute("list1",list);
        request.setAttribute("map",map);
        request.setAttribute("list",poJo);
        request.getRequestDispatcher("demo8/EL.jsp").forward(request,response);
        out.flush();
        out.close();
    /*    拿值默认范围，我没写，所以他是从小找大
                <span>普通 ${requestScope.pt}</span>
<span>对象${dx.getName()}</span>
<span>list:${list1[0].getName()}</span>
<span>map:${map["001"].getName()}</span>*/
    }
}
